package com.atguigu.xuexiplus.mapper;

import com.atguigu.xuexiplus.entity.QuizSubmission;
import org.apache.ibatis.annotations.*;

@Mapper
public interface QuizSubmissionMapper {

    @Insert("INSERT INTO quiz_submission (user_id, subject, total_questions, correct_count, score, submitted_at) " +
            "VALUES (#{userId}, #{subject}, #{totalQuestions}, #{correctCount}, #{score}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(QuizSubmission submission);

    @Update("UPDATE quiz_submission SET correct_count = #{correctCount}, score = #{score} WHERE id = #{id}")
    int updateScore(QuizSubmission submission);

    @Select("SELECT id, user_id AS userId, subject, total_questions AS totalQuestions, correct_count AS correctCount, score, submitted_at AS submittedAt FROM quiz_submission WHERE id = #{id}")
    QuizSubmission findById(@Param("id") Long id);
}


